<template>
	<view class="history_page">
		<view id="head">
			<view class="back" @click="backHome">返回</view>
			<text>{{title}}</text>
		</view>
		<view class="top_step">
			<ryfStep ref="step" v-bind:step.sync="step_id" v-bind:title.sync="title" :stepData="stepList"
			@step_change="step_change" :compeleteList="compeleteList"></ryfStep>
		</view>
		
		<contrastComVue :already="true" :tableData="mccList" v-if="title=='对比评吸'"></contrastComVue>
		<singleHistory :already="true" :tableData="mucList" v-if="title=='单料烟评吸'"></singleHistory>
		<monthlyHistory :already="true" :tableData="mmcList" v-if="title=='单点评吸'"></monthlyHistory>
		<rankHistory :already="true" :tableData="mcscList" v-if="title=='对比排序'"></rankHistory>
		<threeHistory :tableData="mtpcList" v-if="title=='三点评吸'"></threeHistory>
	</view>
</template>

<script>
	import ryfStep from "@/components/ryf-step/step.vue"
	import contrastComVue from "./components/contrastCom.vue";
	import singleHistory from "./components/singleHistory.vue";
	import monthlyHistory from "./components/monthlyHistory.vue";
	import rankHistory from "./components/rankHistory.vue";
	import threeHistory from "./components/threeHistory.vue";
	import { getHistoyByIdAPI } from '@/api/history.js'
	const dict = {
		'mmcList': { name: '单点评吸', classify: 0 },
		'mccList': { name: '对比评吸', classify: 1 },
		'mtpcList': { name: '三点评吸', classify: 2 },
		'mucList': { name: '单料烟评吸', classify: 3 },
		'mcscList': { name: '对比排序', classify: 4 },
	}
	export default {
		components:{ ryfStep, contrastComVue, singleHistory, monthlyHistory, rankHistory, threeHistory },
		data() {
			return {
				stepList:[ 
					{id: 0, name: '单点评吸', classify: 0 },
					{id: 1, name: '对比评吸', classify: 1 },
					{id: 2, name: '三点评吸', classify: 2 },
					{id: 4, name: '单料烟评吸', classify: 4 },
					{id: 5, name: '对比排序', classify: 5 },
				],
				step_id: 0,
				title: "单点评吸",
				compeleteList: {0:true, 1:true, 2:true, 3:true, 4:true, 5:true},
				list: [],
				id: null,
				mccList: [],// 对比评吸
				mcscList: [],// 对比排序
				mmcList: [],// 单点评吸
				mtpcList: [],// 三点评吸
				mucList: [],// 单料烟评吸
			};
		},
		onLoad(options) {
			console.log(options.id)
			this.id = options.id
			if(this.id) {
				this.getData()
			}
		},
		methods:{
			step_change(cid, cname) {
				this.step_title = cname
				this.step_id = cid
			},
			backHome(){
				uni.navigateBack(-1)
			},
			async getData() {
				const res = await getHistoyByIdAPI(this.id)
				console.log("获取到的信息", res)
				if(res.code != 200) return;
				let arr = []
				Object.keys(res.data).forEach(key=>{
					let list = res.data[key]||[]
					if(list.length > 0) {
						this[key] = res.data[key]
						const ele = dict[key]
						arr.push({...ele, id: ele.classify})
					}
				})
				arr.sort((a,b)=>{ return a.classify - b.classify })
				this.stepList = arr
				if(arr.length > 0) {
					this.title = arr[0].name
					this.step_id = arr[0].id
				}
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
